<!-- src/views/DataManagement/components/data-statistics.vue -->
<template>
  <div class="data-statistics-wrapper">
    <div class="data-statistics-header">
      <div class="data-statistics-header-title">{{ title }}</div>
      <div class="data-statistics-header-icon">
        <svg-icon :icon-class="iconClass" style="width: 14px; height: 14px;"></svg-icon>
      </div>
    </div>
    <div class="data-statistics-container">
      <div
        :class="type == 'column' ? 'data-statistics-container-item' : 'data-statistics-container-item data-statistics-container-item-row'"
        v-for="(item, index) in dataObject"
        :key="index"
      >
        <div>
          <svg-icon :icon-class="item.icon"></svg-icon>
          {{ item.name }}
        </div>
        <div :class="item.compare == ''?'data-number  data-number-compare':'data-number'">
          <span>{{ item.Number }}</span>
          {{ item.unit }}
        </div>
        <div class="data-compare">
          <i 
            v-show="item.compareIcon == 'el-icon-right'" 
            class="el-icon-right" 
            style="font-weight: 900;padding-right: 5px;"
          ></i>
          <i 
            v-show="item.compareIcon == 'el-icon-top'" 
            class="el-icon-top" 
            style="font-weight: 900; color: #10b981;padding-right: 5px;"
          ></i>
          <span v-show="item.compare">{{ item.compareText }}</span>
          {{ item.compare }}
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "DataStatistics",
  props: {
    title: {
      type: String,
      default: ""
    },
    iconClass: {
      type: String,
      default: ""
    },
    dataObject: {
      type: Array,
      default: () => []
    },
    type: {
      type: String,
      default: "column"
    }
  }
};
</script>

<style scoped lang="scss">
.data-statistics-wrapper {
  display: flex;
  flex-direction: column;
  height: 100%;
  color: #94a3b8;
}

.data-statistics-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: 30px;
  font-size: 1em;
  
  .data-statistics-header-icon {
    padding: 0.5rem;
    background-color: rgba(59, 130, 246, 0.1);
    border-radius: 50%;
    display: flex;
    align-items: center;
  }
}

.data-statistics-container {
  flex: 1;
  font-size: 0.8em;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  
  .data-statistics-container-item {
    width: 48%;
    height: 48%;
    padding: 0.8em 0;
    background: rgba(255, 255, 255, 0.03);
    border-radius: 8px;
    margin-top: 5px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    align-items: center;
    
    > div {
      width: 80%;
      height: 30%;
      display: flex;
      align-items: center;
    }
    
    .data-number {
      display: flex;
      justify-content: center;
      align-items: baseline;
    }
    .data-number.data-number-compare{
      height: 80%;
      display: flex;
      align-items: flex-end;
    }
    .data-compare{
      display: flex;
      justify-content: flex-end;
    }
    .data-number > span {
      font-size: 1.6em;
      font-weight: 700;
      color: #fff;
      padding-right: 5px;
    }
  }
  
  .svg-icon {
    width: 1.3em;
    height: 1.3em;
    padding-right: 3px;
  }
  
  .data-statistics-container-item.data-statistics-container-item-row {
    width: 24%;
    height: 100%;
  }
}
</style>